//============================================================================//
//                                                                            //
//                              Program/Module                                //
//                                   from                                     //
//                 Selfverifying Solvers for Dense Systems of                 // 
//                     Linear Equations Realized in C-XSC                     //
//                                                                            // 
//                     Carlos Holbig and Walter Kraemer, 2003.                //
//                                                                            //
//       Program developed in C-XSC by Bernardo Frederes Kramer Alcalde,      //
//           Paulo Sergio Morandi Junior and Carlos Amaral Holbig             //
//                                                                            //
//============================================================================//
//----------------------------------------------------------------------------//
// File: lss_aprx (header)                                                    //
// Purpose: Compute an approximate inverse of the square matrix A             //
// Global functions:                                                          //
//   MINV(): Computes the approximate inverse of a square matrix A using the  //
//           Gauss-Jordan algorithm.                                          //
//----------------------------------------------------------------------------//

#ifndef __LSS_APRX_HPP
#define __LSS_APRX_HPP

#include <l_rmatrix.hpp>   // Long Real matrix/vector arithmetic
#include <intvector.hpp>    // Integer vector type
#include <fenv.h>
#include <imatrix.hpp>

#define ROUND_NEAR  FE_TONEAREST
#define ROUND_UP    FE_UPWARD
#define ROUND_DOWN  FE_DOWNWARD


using namespace cxsc;
using namespace std;

//Declaration of LAPACK-routines
extern "C" {
  void dgetri_(int *n, double* A, int *lda, int* ipiv, double* work, int *lwork, int *info);
  void dgetrf_(int *m, int *n, double* A, int *lda, int* ipiv, int *info);
}

//Declaration of BLAS-routines
extern "C" {
   void dgemm_(char *TRANSA, char *TRANSB, int *N, int *M, int *K, 
		       double *ALPHA, double *A, int *LDA, double *B, int *LDB, 
		       double *BETA, double *C, int *LDC);
   void zgemm_(char *TRANSA, char *TRANSB, int *N, int *M, int *K, 
		       double *ALPHA, double *A, int *LDA, double *B, int *LDB, 
		       double *BETA, double *C, int *LDC);		       
}

extern int minv(rmatrix&);

extern void lapackMatInv(rmatrix &A, rmatrix &R, int& error);

#endif

